package com.cocola.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cocola.mapper.EducationMapper;
import com.cocola.pojo.Education;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class EducationSercice {

    @Autowired
    private EducationMapper educationMapper;

    public List<Education> findEducation() {
        return educationMapper.selectList(null);
    }

    /**
     * 查找匹配条件 userName 的全部
     */
    public List<Education> finOneEducation(String userName) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("user_name", userName);

        return educationMapper.selectByMap(map);
    }

    /**
     * add
     */
    public void add(String graduationDate, String educationNum, String educationLeval,
                    String educationSchool, String educationType, String educationMajor,
                    String educationDegree, String certificateNumber, String userName) {

        Education education = new Education();
        education.setGraduationDate(graduationDate);
        education.setEducationNum(educationNum);
        education.setEducationLeval(educationLeval);
        education.setEducationSchool(educationSchool);
        education.setEducationType(educationType);
        education.setEducationMajor(educationMajor);
        education.setEducationDegree(educationDegree);
        education.setCertificateNumber(certificateNumber);
        education.setUserName(userName);

        educationMapper.insert(education);

    }

    /**
     * update
     */
    public void update(String graduationDate, String educationNum, String educationLeval,
                       String educationSchool, String educationType, String educationMajor,
                       String educationDegree, String certificateNumber, String userName) {

        Education education = new Education();
        education.setGraduationDate(graduationDate);
        education.setEducationNum(educationNum);
        education.setEducationLeval(educationLeval);
        education.setEducationSchool(educationSchool);
        education.setEducationType(educationType);
        education.setEducationMajor(educationMajor);
        education.setEducationDegree(educationDegree);
        education.setCertificateNumber(certificateNumber);

        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.eq("user_name", userName);
        educationMapper.update(education, wrapper);
    }



    /**
     * delete
     */
    public void delete(String certificateNumber) {

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("certificate_number", certificateNumber);
        educationMapper.delete(wrapper);
    }
}
